package com.mach.platform.api.repository;

import com.mach.platform.api.domain.WxUser;
import com.mach.platform.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface WxUserRepo extends BaseRepository<WxUser> {

    /**
     * 通过openId查询小程序用户
     * @param openId
     * @return
     */
    WxUser findByOpenId(String openId);

    /**
     * 删除小程序用户信息
     * @param openId
     * @return
     */
    @Modifying
    @Query(name = "delete from wx_user where open_id = ?1", nativeQuery = true)
    int deleteByOpenId(String openId);

    /**
     * 查询团队/站房下面的所有成员信息
     * @param stationId
     * @return
     */
    @Query(value = "select t.open_id, u.nick_name, u.avatar_path, t.is_leader from team t left join wx_user u on t.open_id = u.open_id where t.station_id = ?1", nativeQuery = true)
    List<Map> findTeamMemberByStationId(Long stationId);

}
